<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数</title>
</head>

<body>

<!--
    函数的定义方式
    1. 声明函数
    2. 匿名函数
    3. new Function("a","b","alert(a+b)") --考题
    定义函数关键字: function
    -->
<script>
    //无参无返回值
    function f() {
        document.write("hello" + "<br>");
    }

    //调用方法
    f();

    //有参有返回值
    function f1(a, b) {
        return a + b;
    }

    let result = f1(1, 2);
    document.write(result + "<br>");

    //可变参数
    function f2(...parm) {
        let sum = 0;
        for (let i = 0; i < parm.length; i++) {
            sum += parm[i]
        }
        return sum;
    }

    let result2 = f2(10, 20, 30);
    document.write(result2 + "<br>")

    //匿名函数
    let f3 = function () {
        document.write("helloJs" + "<br>");
    }
    f3();


</script>

</body>
</html>